package heathot.servlet;

import heathot.bookservice.BookService;
import heathot.bookservice.BookServiceimpl;
import heathot.entiy.Car;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class DeleteCarItemServlet extends HttpServlet {

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter out = response.getWriter();
		String id = request.getParameter("id");
		int bookId = 0;
		if(id!=null&&!"".equals(id)){
			bookId = Integer.parseInt(id);
		}
		HttpSession session = request.getSession();
		Car car = (Car)session.getAttribute("car");
		if(car==null){
			 car = new Car();
			 session.setAttribute("car",car);
		}
		BookService service = new BookServiceimpl();
		service.deleteCar(bookId, car);
		session.setAttribute("car",car);
		request.getRequestDispatcher("/viewcar.jsp").forward(request,response);
		out.flush();
		out.close();
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		
		out.flush();
		out.close();
	}
}
